package com.yiren.backstage.judge.services.sczb.impl;

import com.yiren.backstage.currency.bean.CarStateBean;
import com.yiren.backstage.currency.enums.CarStateValueEnum;
import com.yiren.backstage.currency.enums.ResultStateEnum;
import com.yiren.backstage.judge.services.sczb.ICheckDetourService;

/**
 * Time:2022/4/7 10:43
 * Author:xiaozan
 * Description：检测绕车服务实现
 */
public class CheckDetourServiceImpl implements ICheckDetourService {

    private CarStateBean carStateBean;

    private boolean headLeft;

    private boolean headRight;

    private boolean tailLeft;

    private boolean tailRight;

    private boolean seat;

    private boolean rearviewMirror;

    private boolean reflectorMirror;

    public CheckDetourServiceImpl(){
        carStateBean = CarStateBean.getInstance();
    }

    @Override
    public ResultStateEnum twoDetour(){
        if(carStateBean.getCarTailLeft() == CarStateValueEnum.PASS || carStateBean.getCarTailRight() == CarStateValueEnum.PASS){
            tailLeft = true;
        }
        if(carStateBean.getCarHeadLeft() == CarStateValueEnum.PASS || carStateBean.getCarHeadRight() == CarStateValueEnum.PASS){
            if(tailLeft){
                return ResultStateEnum.SUCCESS;
            }else{
                //扣分 未逆时针绕车
                return ResultStateEnum.FAIL;
            }
        }
        return ResultStateEnum.EXECUTING;
    }

    @Override
    public ResultStateEnum fourDetour(){
        if(carStateBean.getCarTailLeft() == CarStateValueEnum.PASS){
            tailLeft = true;
        }

        if(carStateBean.getCarTailRight() == CarStateValueEnum.PASS){
            //扣分 未逆时针绕车
            if(!tailLeft)  return ResultStateEnum.FAIL;
            tailRight =true;
        }

        if(carStateBean.getCarHeadRight() == CarStateValueEnum.PASS){
            //扣分 未逆时针绕车
            if(!tailLeft || !tailRight)  return ResultStateEnum.FAIL;
            headRight = true;
        }

        if(carStateBean.getCarHeadLeft() == CarStateValueEnum.PASS){
            if(tailLeft && tailRight && headRight){
                return ResultStateEnum.SUCCESS;
            }else{
                //扣分 未逆时针绕车
                return ResultStateEnum.FAIL;
            }
        }
        return ResultStateEnum.EXECUTING;
    }

    @Override
    public ResultStateEnum threeAdjustment() {
        if(carStateBean.getSeat() == CarStateValueEnum.ADJUST) seat = true;
        if(carStateBean.getRearviewMirror() == CarStateValueEnum.ADJUST) rearviewMirror = true;
        if(carStateBean.getReflectorMirror() == CarStateValueEnum.ADJUST) reflectorMirror = true;

        if(seat && rearviewMirror && reflectorMirror) return ResultStateEnum.SUCCESS;

        return ResultStateEnum.EXECUTING;
    }
}
